<template>
    <a-dropdown>
        <div class="header-avatar" style="cursor: pointer">
            <a-avatar
                :src="user.avatar === undefined ? '@/assets/img/logo.58c9d85b.png' : user.avatar"
                class="avatar" shape="circle"
                size="small"/>
            <span class="name" v-text="username"></span>
        </div>
        <a-menu slot="overlay" :class="['avatar-menu']">
            <!--      <a-menu-item>-->
            <!--        <a-icon type="user"/>-->
            <!--        <span>个人中心</span>-->
            <!--      </a-menu-item>-->
            <a-menu-item>
                <a-icon type="dashboard"/>
                <span @click="$router.push('/showstand')">进入展示台</span>
            </a-menu-item>
            <!--      <a-menu-divider/>-->
            <a-menu-item @click="logout">
                <a-icon style="margin-right: 8px;" type="poweroff"/>
                <span>退出登录</span>
            </a-menu-item>
        </a-menu>
    </a-dropdown>
</template>

<script>
import {mapGetters} from 'vuex'
import {logout} from '@/services/user'
import {METHOD, request} from "../../utils/request";

export default {
    name: 'HeaderAvatar',
    data() {
        return {
            username: null,
        }
    },
    computed: {
        ...mapGetters('account', ['user', 'adminUser', 'roles']),
    },
    mounted() {
        console.log("header avatar" + typeof this.roles);

        this.username = this.user.username;
    },
    methods: {
        logout() {
            logout()

            request("/adminLgoin/loginout", METHOD.POST, null,
                {
                    params: {type: 1}
                })

            this.$router.push('/login')
        }
    }
}
</script>

<style lang="less">
.header-avatar {
    display: inline-flex;

    .avatar, .name {
        align-self: center;
    }

    .avatar {
        margin-right: 8px;
    }

    .name {
        font-weight: 500;
    }
}

.avatar-menu {
    width: 150px;
}

</style>
